import java.net.*;
import java.io.*;

public class EchoServer
{
	public static void main(String args[])
	{
		ServerSocket serverSocket = null;
		Socket socket = null;
		InputStream inp = null;
		BufferedReader brinp = null;
		DataOutputStream out = null;
		PrintWriter outp = null;
		try{
		outp = new PrintWriter(new OutputStreamWriter(System.out, "Cp852"), true);
		}
		catch(UnsupportedEncodingException e){
			System.out.println("Nie mona ustawi strony kodowej Cp852.");
			outp = new PrintWriter(new OutputStreamWriter(System.out), true);
		}
		try{
			serverSocket = new ServerSocket(6666);
		}
		catch(IOException e){
			outp.println("Bd przy tworzeniu gniazda serwerowego.");
			System.exit(-1);
		}
		outp.println("Inicjalizacja gniazda zakoczona...");
		outp.println("Parametry gniazda: " + serverSocket);
		while(true){
			try{
				socket = serverSocket.accept();
			}
			catch(IOException e){
				outp.println("Bd wejcia-wyjcia: " + e);
			}
			outp.println("Nadeszo poczenie...");
			outp.println("Parametry poczenia: " + socket);
			new EchoServerThread(socket).start();
		}
	}
}
